package io.dora.zk;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

public class ZkPublishTest {
	
	private ZooKeeper zk;

	public void createInstance() throws Exception {
		zk = new ZooKeeper("localhost:2181", 3000, new Watcher() {
			public void process(WatchedEvent event) {
				System.out.println(event.toString());
			}
		});
	}
	
	public void setData() throws Exception {
		String data = "10.28.162.12:36600,10.28.162.12:36601";
		zk.setData("/jshop-cx/com.jd.jshop.rpc.face.HelloRpc", data.getBytes(), -1);
	}
	
	public void close() {
		try {
			zk.close();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		zk = null;
	}


	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		ZkPublishTest zst = new ZkPublishTest();
		zst.createInstance();
		Thread.sleep(500);
		zst.setData();
		//zst.close();
	}

}
